package com.woniuxy.automotivemanagementsystem.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@AllArgsConstructor
@Data
@NoArgsConstructor
@RestController
@RequestMapping("/result")
public class Result {
    private Integer code;
    private Boolean success;
    private String message;
    private Object data;

    static public Result success(Object data)
    {
        Result result = new Result();
        result.setCode(200);
        result.setSuccess(true);
        result.setMessage("操作成功");
        result.setData(data);
        return result;
    }
    static public Result error(String message)
    {
        Result result = new Result();
        result.setCode(500);
        result.setSuccess(false);
        result.setMessage(message);
        result.setData(null);
        return result;
    }
    public Result code(Integer code){
        this.setCode( code);
        return this;
    }
    public Result message(String message){
        this.setMessage( message);
        return this;
    }
    public Result data(Object data){
        this.setData( data);
        return this;
    }
    private Result success(Boolean success){
        this.setSuccess( success);
        return this;
    }
}
